<!doctype html>
<html lang="en">

	<head>
		<meta charset="UTF-8">
		<title>手势锁屏示例</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<!--标准mui.css-->
		<link rel="stylesheet" href="../../../css/mui.min.css">
		<!--App自定义的css-->
		<link rel="stylesheet" type="text/css" href="../../../css/app.css" />
		<style>
			html,
			body {
				width: 100%;
				height: 100%;
				margin: 0px;
				padding: 0px;
				overflow: hidden;
				background-color: #efeff4;
			}
			
			#holder {
				width: 300px;
				height: 300px;
				border: solid 1px #bbb;
				border-radius: 5px;
				margin: 50px auto;
				background-color: #fff;
			}
			
			#alert {
				text-align: center;
				padding: 20px 10px;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">输入手势解锁</h1>
		</header>
		<div class="mui-content">
			<div id='holder' class="mui-locker" data-locker-options='{"ringColor":"rgba(210,210,210,1)","fillColor":"#ffffff","pointColor":"rgba(0,136,204,1)","lineColor":"rgba(0,136,204,1)"}' data-locker-width='300' data-locker-height='300'></div>
			<div id='alert'></div>
		</div>

		<script src="../../../js/mui.min.js"></script>
		<script src="../../../js/mui.locker.js"></script>
		<script type="text/javascript" src="../../../js/app.js"></script>
		<script>
			(function($, doc) {
				$.init();
				var holder = doc.querySelector('#holder'),
					alert = doc.querySelector('#alert'),
					record = [],
					flag = false;
				var recodePage = mui.preload({
					"id": 'recode',
					"url": 'recode.html'
				});
				var toRecode = function() {
					mui.fire(recodePage, 'show', null); //加载数据
					mui.openWindow({
						id: 'recode',
						show: {
							autoShow: true
						}
					});
				};
				//处理事件
				holder.addEventListener('done', function(event) {
					var rs = event.detail;
					if(app.getUser().locker) {
						if(app.getUser().locker == rs.points.join('')) {
							flag = true;
						}
					} else {
						if(rs.points.length < 4) {
							alert.innerText = '设定的手势太简单了';
							record = [];
							rs.sender.clear();
							return;
						}
						console.log(rs.points.join(''));
						record.push(rs.points.join(''));
						if(record.length >= 2) {
							if(record[0] == record[1]) {
								alert.innerText = '手势设定完成';
								flag = true;
							} else {
								alert.innerText = '两次手势设定不一致';
							}
							rs.sender.clear();
							record = [];
						} else {
							alert.innerText = '请确认手势设定';
							rs.sender.clear();
						}
					}
					if (flag) {
						toRecode();
					}
				});
			}(mui, document));
		</script>
	</body>

</html>